<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;
class ActivityController extends PublicController {
	
	
	//活动商品列表
	public function listAction(){
		
		
		$calist=$this->pagelist();
		
		foreach($calist['list'] as $k=>$v){
			
			$calist['list'][$k]['preferential']=$v['atype']?($v['price']*($v['avalue']/10)):($v['price']-$v['avalue']);
			
		}
		
		$this->assign('list',$calist['list']);

		$this->assign('page',$calist['page']);

		$this->view();
	}


	/*
	*/
	public function getActivity(){
		$Model=D("GoodsNActivity"); // 实例化对象			
		$list=$Model->field('goodsid')->select();
		$alist=array();
		foreach($list as $key=>$val){
			$alist[]=$val['goodsid'];
			}
			return $alist;
	}

	
	public function pagelist(){
       
		$Model=D('Goods');
		
		$liaid=$this->getActivity();

		if(!empty($liaid)){
			$map['id']  = array('in',$liaid);	
		}
		
		$count      = $Model->where($map)->count();// 查询满足要求的总记录数
		//echo $Model->getlastsql();
		$Page       = new \Think\Page($count,8);// 实例化分页类 传入总记录数和每页显示的记录数		
		$Page->setConfig('prev','上一页');
		$Page->setConfig('next','下一页');
		$Page->setConfig('first','首页');
		$Page->setConfig('last','尾页');		
		$Page->setConfig('header','<li><span class="rows">共 %TOTAL_ROW% 条记录</span></li>');		
		$Page->setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %PAGES%');		
		$list = $Model->where($map)->relation('_Activity')->order(" id desc ")->limit($Page->firstRow.','.$Page->listRows)->select();
		$show       = $Page->show();// 分页显示输出
		
		return array('list'=>$list,'page'=>$show);
		
	}

	
}